//
//  XJ_ShoukuanViewController.m
//  XunJieProject
//
//  Created by xue on 2018/6/20.
//  Copyright © 2018年 Soowin. All rights reserved.
//

#import "XJ_ShoukuanViewController.h"
#import "ZDXTabBarControllerViewController.h"

@interface XJ_ShoukuanViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet ZDXXibLabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *up_phoneView;
@property (weak, nonatomic) IBOutlet UIButton *shouqianBtn;
@property (nonatomic,strong) NSString *billNo;
@end

@implementation XJ_ShoukuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    NSString *phoneStr =[NSString stringWithFormat:@"%@",_phone];
    if (phoneStr.length>8) {
        phoneStr =[phoneStr stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    }
    self.phoneLabel.text =[NSString stringWithFormat:@"请输入手机号%@收到的验证码",phoneStr];
    
    [self loadPhoneCode];
}

-(void)creatMainUI{
    
    self.nav_titleLabel.text =@"取现";
    _up_phoneView.constant =SafeAreaTopHeight;
//    _codeTF.keyboardType =UIKeyboardTypeNumberPad;
    _codeTF.delegate =self;
    [_codeTF addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    _shouqianBtn.layer.cornerRadius =CGRectGetHeight(_shouqianBtn.frame)/2;
    _shouqianBtn.layer.masksToBounds =YES;
    _shouqianBtn.backgroundColor =Color_ZhuSeDiao;
}
- (IBAction)Click_btn:(id)sender {
    
    if (_codeTF.text.length==0) {
        [XJ_Utils alertViewWithMessage:@"请输入手机验证码"];
        
        return;
    }
    
    
    [self loadMoneyCollectSubmit];
}
#pragma mark--收钱确定接口
-(void)loadMoneyCollectSubmit{
    
    NSUserDefaults * db = [NSUserDefaults standardUserDefaults];
    NSString * token = [db objectForKey:@"token"];
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:IDENTIFIER forKey:@"equipmentNo"];
    [dic setValue:STSTERMVERSION forKey:@"systemVersion"];
    [dic setValue:APPVERSION forKey:@"appVersion"];
    [dic setValue:USERID forKey:@"userId"];
    [dic setValue:token forKey:@"token"];
    
    [dic setValue:_collectMoney forKey:@"collectMoney"];//收款金额
    [dic setValue:_CollectPlans_model.collectPlanId forKey:@"collectPlanId"];//收款方案Id
    [dic setValue:_CreditCard_model.creditCardId forKey:@"creditCardId"];//信用卡Id
    [dic setValue:_CreditCard_model.cardNo forKey:@"creditCardNo"];//信用卡号码
    [dic setValue:_DepositCard_model.depositCardId forKey:@"depositCardId"];//储蓄卡Id
    [dic setValue:_DepositCard_model.cardNo forKey:@"depositCardNo"];//储蓄卡号码
    [dic setValue:_phone forKey:@"mobile"];//手机号码
    [dic setValue:_codeTF.text forKey:@"code"];//短信的code
    [dic setValue:_billNo forKey:@"billNo"];//提现订单号
    [XJ_Utils signPost:@"/money/collectSubmit?" parameters:dic success:^(NSInteger recode, id jsonObject) {
        
        
//        NSDictionary * dataDic = [jsonObject objectForKey:@"data"];
        ZDXAlertView *alext =[[ZDXAlertView alloc]initWithMessage:@"取现成功" image:@"pop_msg_succeed_xs"];
        [alext showXLAlertView];
        
        ZDXTabBarControllerViewController *tab =(ZDXTabBarControllerViewController*)KWINDOW.rootViewController;
        [tab setSelectedIndex:1];
        
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
    
    
}

#pragma mark--获取手机号验证码
-(void)loadPhoneCode{
    
    NSUserDefaults * db = [NSUserDefaults standardUserDefaults];
    NSString * token = [db objectForKey:@"token"];
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    [dic setValue:IDENTIFIER forKey:@"equipmentNo"];
    [dic setValue:APPVERSION forKey:@"appVersion"];
    [dic setValue:STSTERMVERSION forKey:@"systemVersion"];
    [dic setValue:USERID forKey:@"userId"];
    
    if (token!=nil &&![token isEqualToString:@""]) {
        
        [dic setValue:token forKey:@"token"];
        
    }
    [dic setValue:_CreditCard_model.creditCardId forKey:@"creditCardId"];
    [dic setValue:_collectMoney forKey:@"collectMoney"];
    [dic setValue:_phone forKey:@"mobile"];
    
    
    [XJ_Utils signPost:@"/money/collectSendMsg?" parameters:dic success:^(NSInteger recode, id jsonObject) {
        
        [XJ_Utils alertViewWithMessage:@"验证码发送成功"];
        NSDictionary * dataDic = [jsonObject objectForKey:@"data"];
        NSString *billNoStr =dataDic[@"billNo"];
        self.billNo =billNoStr;
        
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
}

- (void)textFieldDidChange:(UITextField *)textField

{
    
    if (textField == self.codeTF) {
        
        if (textField.text.length > 6) {
            
            textField.text = [textField.text substringToIndex:6];
            
        }
        
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
